package pro.cherish.knowledgeumldesignpattern.designPattern.com.cherish.proxy.JdkProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class StarHandler implements InvocationHandler {

    private Star realStar;

    public StarHandler(RealStar realStar) {
        this.realStar=realStar;

//        原理一致，只是书写方式不一致
//        Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(),realStar.getClass().getInterfaces(),this);
    }

    //    调用所有方法都会来次执行
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("******");
        Object o=null;
        System.out.println("正在方法前");
        System.out.println("面谈，签合同，预付款，订机票");
/*        if(method.getName().equals("sing")){
            o=method.invoke(realStar,args);
        }*/
        o=method.invoke(realStar,args);
        System.out.println("正在方法后");
        System.out.println("收钱");
        return o;
    }
}
